package com.ehsy.statement;

import com.dtflys.forest.Forest;
import com.dtflys.forest.config.ForestConfiguration;
import com.ehsy.common.ResponseVo;
import com.ehsy.config.MyBackend;
import com.ehsy.model.UserInfo;
import com.ehsy.service.BackendService;
import com.ehsy.service.UrlParamService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

/**
 * @author YanZhen_Li
 * @version 1.0
 * @title A6后端框架
 * @description 我们的 foreset 支持多种请求框架，这个测试类主要讲解我们的我们的请求框架的使用方式
 * @create 2024/6/18 10:02
 */
@SpringBootTest
//        (webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
//        properties = {"spring.config.location=classpath:custom-test-application.yml"})
public class A6后端框架 {
    @Resource
    UrlParamService service;

    @Resource
    BackendService backendService;

    /**
     * 全局配置文件测试
     * ! 需要头部环境
     */
    @Test
    public void test001(){
        UserInfo userInfo = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        ResponseVo<UserInfo> test6 = service.send6(userInfo);
        System.out.println(test6);
    }
    /**
     * 代码配置你后端框架
     */
    @Test
    public void test002(){
        UserInfo userInfo = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        // 获取Forest全局配置对象
        ForestConfiguration configuration = Forest.config();
        // ? 设置全局后端框架为 httpclient
        configuration.setBackend(MyBackend.HTTPCLIENT);
        ResponseVo<UserInfo> test6 = service.send6(userInfo);
        System.out.println(test6);
        // ? 设置全局后端框架为 httpclient
        configuration.setBackend(MyBackend.OKHTTP3);
        test6 = service.send6(userInfo);
        System.out.println(test6);
    }

    /**
     * 接口请求后端框架配置
     * 两种配置注解方式，三种注解使用方法
     */
    @Test
    public void test003(){
        UserInfo userInfo = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        ResponseVo<UserInfo> test1 = backendService.test1(userInfo);
        ResponseVo<UserInfo> test2 = backendService.test2(userInfo);
        ResponseVo<UserInfo> test3 = backendService.test3(userInfo);
        ResponseVo<UserInfo> test4 = backendService.test4(userInfo);
        ResponseVo<UserInfo> test5 = backendService.test5("httpclient", userInfo);
        System.out.println(test1);
        System.out.println(test2);
        System.out.println(test3);
        System.out.println(test4);
        System.out.println(test5);
    }
    /**
     * 自定义后端Client对象
     */
    @Test
    public void test004(){
        UserInfo userInfo = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        ResponseVo<UserInfo> test6 = backendService.test6(userInfo);
        ResponseVo<UserInfo> test7 = backendService.test7(userInfo);
        System.out.println(test6);
        System.out.println(test7);
    }

    /**
     * 如果您不想让某个方法的请求的 Client 实例由 Forest 的缓存来管理，也可以使用@BackendClient注解来打开/关闭其缓存。
     */
    @Test
    public void test005(){
        UserInfo userInfo = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        ResponseVo<UserInfo> test8 = backendService.test8(userInfo);
        System.out.println(test8);
    }
}
